<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-radio-group v-model="current" @input="stateHandel">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button
          :label="item.value"
          v-for="(item, index) in dict.type.dict_audit_state"
          :key="index"
          >{{ item.label }}</el-radio-button
        >
      </el-radio-group>
    </el-row>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="房源" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承租人" prop="lodgerName">
        <el-input
          v-model="queryParams.lodgerName"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="lodgerPhone">
        <el-input
          v-model="queryParams.lodgerPhone"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="roomList"
      @selection-change="handleSelectionChange"
      ref="table"
    >
      <el-table-column
        label="房源"
        prop="address"
        :show-overflow-tooltip="false"
      />
      <el-table-column label="承租信息" prop="" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <div>{{ scope.row.lodgerName }}</div>
          <div>{{ scope.row.lodgerPhone }}</div>
        </template>
      </el-table-column>
      <el-table-column label="金额" prop="checkInTime">
        <template slot-scope="scope">
          <div>租金：{{
              scope.row.order.depositPaidNumber
            }}</div>
          <div>押金：{{ scope.row.order.deposit }}</div>
        </template>
      </el-table-column>
      <el-table-column label="入住时间" prop="checkInTime">
        <template slot-scope="scope">
          <div>
            入住：{{ scope.row.order.checkInTime | formatDate("YYYY-MM-DD") }}
          </div>
          <div>
            退租：{{ scope.row.order.checkOutTime | formatDate("YYYY-MM-DD") }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="auditRecordState">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.dict_audit_state"
            :value="scope.row.auditRecordState"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="detailHandel(scope.row)"
            >详情</el-button
          >
          <el-button
            type="text"
            v-if="scope.row.auditRecordState == 1"
            @click="checkHandel(scope.row)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <sign-check
      v-model="signDialogVisible"
      :recordId="recordId"
      :isDetail="isDetail"
      @success="handleQuery"
    ></sign-check>
  </div>
</template>

<script>
import { auditRecord } from "@/api/order/order";
import signCheck from "./componet/sign-check.vue";
export default {
  name: "orderList",
  dicts: ["dict_audit_state"],
  components: { signCheck },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      roomList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 当前选择
      current: "",
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],

      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roomNumber: undefined,
        address: undefined,
        status: undefined,
        orderState: undefined,
        lodgerName: "",
        lodgerPhone: "",
        auditRecordType: 1, //审核记录类型：1签约 2退租 3换房 4转租 5续租
      },
      countHouseList: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        roomNumber: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" },
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" },
        ],
      },
      detailDialogVisible: false,
      recordId: "",
      openChangeHouse: false,
      openEdit: false,
      orderInfo: {},
      addDialogVisible: false, //新建弹窗，
      openmembershipRegistration: false,
      isDetail: false, //是否编辑成员
      signDialogVisible: false,
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    detailHandel(row) {
      this.isDetail = true;
      this.recordId = row.recordId;
      this.signDialogVisible = true;
    },
    checkHandel(row) {
      this.isDetail = false;
      this.recordId = row.recordId;
      this.signDialogVisible = true;
    },
    dialogClose() {
      this.openChangeHouse = false;
      this.openEdit = false;
      this.openmembershipRegistration = false;
      this.getList();
    },
    stateHandel(i) {
      this.queryParams.auditRecordState = i;
      this.handleQuery();
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      auditRecord(this.queryParams, this.dateRange).then((response) => {
        this.roomList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.orderId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.queryParams.orderIds = this.ids;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.orderId = "";
      this.addDialogVisible = true;
    },
    // 详情操作
    handleDetail(row) {
      this.orderId = row.orderId;
      this.detailDialogVisible = true;
    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.orderInfo = row;
      this.openEdit = true;
    },
    //换房操作
    handleChangeHouse(row) {
      this.orderInfo = row;
      this.openChangeHouse = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "enterprise/order/order/export",
        {
          ...this.queryParams,
        },
        `订单_${new Date().getTime()}.xlsx`
      );
    },
    //请空选择项
    clearSelect() {
      this.$refs.table.clearSelection();
    },
  },
};
</script>
<style lang="scss" scoped>
.title {
  font-size: 14px;
  font-weight: 500;
  color: #666;
}
.total {
  font-size: 18px;
  font-weight: 500;
  color: #333;
  margin-top: 6px;
}
.left-border {
  border-left: 1px solid #999;
}
.right-border {
  border-right: 1px solid #999;
}
.info {
  padding: 10px 15px;
  margin: 15px 0;
  background: #e6f7ff;
  color: #1890ff;
  span {
    color: #565c5f;
  }
  .clear {
    margin-left: 20px;
    cursor: pointer;
  }
}
</style>
